import { AddAdress } from '@/api/api'
import { useRouter } from "vue-router";
import { showToast } from "vant";



export const AddAress = () => {
    const userid = localStorage.getItem('userId')
    const router = useRouter()
    const toSave = async (e:any) => {        
        const params = {
            name: e.name,
            tel: e.tel,
            province: e.province,
            city: e.city,
            county: e.county,
            userid: userid,
            addressDetail: e.addressDetail,
            isDefault: e.isDefault
        }
        const res = await AddAdress(params)
        if (res.data.code === '200') {
            showToast({
                message: '添加成功',
                position: 'middle'
            })
            router.push('/addres')
        }
        
    }
    return {toSave}
}
